package com.iti.jets.gpts.home;

// default package
// Generated Mar 22, 2014 9:41:00 PM by Hibernate Tools 3.4.0.CR1

import com.iti.jets.gpts.dao.AbstractDAO;
import com.iti.jets.gpts.pojo.Point;
import com.iti.jets.gpts.pojo.TranService;
import com.iti.jets.gpts.pojo.TranServiceRoute;
import java.util.ArrayList;
import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;

/**
 * Home object for domain model class TranServiceRoute.
 *
 * @see .TranServiceRoute
 * @author Hibernate Tools
 */
public class TranServiceRouteHome extends AbstractDAO<TranServiceRoute> {

    public TranServiceRouteHome(SessionFactory sessionFactory) {
        super(sessionFactory);
    }

    public ArrayList<TranService> searchByPoint(Point p1) {
        ArrayList<TranService> route = new ArrayList();
        Criteria criteria = session.createCriteria(TranService.class, "ts")
                .add(Restrictions.eq("tsr.point", p1));
        List result = criteria.setProjection(Projections.property("tranService")).list();
        
        TranService service;
        if (result.size() > 0) {
            for (Object c : result) {
                service = (TranService) c;
                route.add(service);
                return route;
            }
        }
        return null;
    }
     
    public ArrayList<TranService> searchByMorePoint(List<Point> pointsList) {
        ArrayList<TranService> route = new ArrayList();
        Criteria criteria = session.createCriteria(TranService.class, "ts");
        for(int i=0;i<pointsList.size();i++){
        
        criteria = criteria.add(Restrictions.eq("ts.point", pointsList.get(i)));
        }
        List result = criteria.setProjection(Projections.groupProperty("tranService")).list();
        
        TranService service;
        if (result.size() > 0) {
            for (Object c : result) {
                service = (TranService) c;
                route.add(service);
                return route;
            }
        }
        return null;
    }

    
}
